from plotter import *
from fit import *
import pylab as plt
import scipy as spy
import numpy as np
import scipy.stats as stats

class QQPlot:
    def __init__(self,data):
        logdata = spy.log(np.array(data,dtype='float'))
        n = len(logdata)
        mu = sum(logdata)/n
        sigma = sum((i-mu)**2 for i in logdata)/(n-1)
        sigma = sigma**0.5
        self.data = (logdata-mu)/sigma

    def lognormal_plot(self):
#        p = Plotter(self.data)
#        x = p.x
#        c = p.c
#        l = LogNormalFit(self.data)
#        l.fit()
#        xf,cf = l.fitted_ccdf()
#        print len(c), len(cf)
        (x,y), (slope, inter, cor) = stats.probplot(self.data, dist='norm')
        osmf = x.take([0, -1])  # endpoints
        osrf = slope * osmf + inter
        return x,y
#        plt.figure()
#        plt.plot(x, y, ',', osmf, osrf, '-')
#        #plt.plot(c,cf,'ko')
#        #plt.plot([0,1],[0,1],'k-')
#        plt.show()

    def t_plot(self):
        df = len(self.data)
        (x,y), (slope, inter, cor) = stats.probplot(self.data, sparams=(df),dist='t')
        osmf = x.take([0, -1])  # endpoints
        osrf = slope * osmf + inter
        return x,y
#        plt.figure()
#        plt.plot(x, y, ',', osmf, osrf, '-')
#        #plt.plot(c,cf,'ko')
#        #plt.plot([0,1],[0,1],'k-')
#        plt.show()

